#pragma once
#include <iostream>

#include <ctime>
#include <cstring>

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>
#include <sys/shm.h>
#include <unistd.h>
using namespace std;

#define PATH_NAME "./"
#define FIFO_FILE ".fifo" //命名管道
#define MEM_SIZE 4096 //共享内存大小
#define PROJ_ID 0x6666

std::ostream &log()
{
    cout << "for debug | " << "timestamp:" 
    << (time_t)time(nullptr) << endl; // time_t : long int
    return cout;
}

key_t CreateKey()
{
    key_t key = ftok(PATH_NAME, PROJ_ID);
    if (key < 0)
    {
        cerr << "create key error:" << strerror(errno) << endl;
        exit(1);
    }
    return key;
}

//用命名管道自带访问控制的特性，来对共享内存进行访问控制
void CreateFifo()
{
    umask(0);
    if(mkfifo(FIFO_FILE,0666)!=0)
    {
        log()<<strerror(errno)<<endl;
        exit(2);
    }
}


